home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / mony_121.zip / MONY_API.C < prev    next >
C/C++ Source or Header  |  1996-03-21  |  14KB  |  529 lines

  1. /* mony_api.c   */
  2. /* 24-Jan-96 - original (chh) */
  3.  
  4. // 21-Mar-96 - See EMX_MONY.ZIP for alternate source and header files
  5.  
  6. // ------------------------------------------------------------
  7. //
  8. // A simplified API for using the Mony MDA BIOS emulator driver
  9. // for HLL access follows after this IDC-access description for
  10. // DD programmers.  The protos/structures are in mony_api.h.
  11. //
  12. // ------------------------------------------------------------
  13. // For IDC/device driver access, use:
  14. //
  15. // AttachDD to the Mony driver at init or task time (MONY.SYS must already be loaded).
  16. //
  17. // IDCstruc STRUC
  18. //  userRez        WORD 3 DUP (0)
  19. //  entryPtr       WORD 0
  20. //  entrySel       WORD 0
  21. //  entryDS        WORD 0
  22. // IDCstruc ENDS
  23. //
  24. // IDCname      BYTE "MONY$   "         ;that's MONY$ followed by 3 spaces
  25. // IDC          IDCstruc <>             ;as defined above
  26. //
  27. // ;attach to MONY$ driver if available
  28. //
  29. //      mov     bx,OFFSET IDCname
  30. //      mov     di,OFFSET IDC
  31. //      mov     dl,42           ;ATTACH_DD in devhlp.inc
  32. //      call    [Device_Help]
  33. //      jc      @F
  34. //      ...
  35. //
  36. // ;You cannot call Mony during your device driver init since you are at ring3.
  37. // ;You have to wait for task (kernel/strategy/IOCtl) or interrupt time.
  38. // ;For example, in a generic IOCtl call you can print a string by:
  39. //
  40. //      sub     al,al                  ;al=0: bl=attr ,cursorPos not updated
  41. //      mov     bx,0007h               ;bh=page, (bl=attr if al=0/1)
  42. //      mov     cx,SIZEOF stringMsg    ;cx=string length
  43. //      mov     dx,0100h               ;dh=row, dl=col
  44. //      mov     di,OFFSET stringMsg    ;es:di->string
  45. //      push    ds
  46. //      pop     es
  47. //      mov     ah,13h
  48. //      ;awkward loading ds, so I do it for you (i.e., don't load ds=IDC.entryDS)
  49. //      call    DWORD PTR IDC.entryPtr
  50. //      sub     ax,ax
  51. //
  52. // ;The virtual address must be global (i.e., in the GDT).  Shouldn't be a problem,
  53. // ;but if it is (an LDT entry), just use Device_Help to make a suitable pointer.
  54. //
  55. // ;As you see, pointers down here are now virtual (sel:off), and can be easily used.
  56. // ;Unlike BIOS, I don't use BP for passing data.  Instead, di is used whenever
  57. // ;a pointer offset is required.  Functions 13h, 14h, 15h, and 1Bh uses es:di
  58. // ;(the pointer use should be obvious).  Register arguments are like the standard
  59. // ;INT10 interface.  Consult the mony_api.c file for any exceptions with regard
  60. // ;to registers ax,bx,cx,dx (there may not be any exceptions, except that BP is
  61. // ;not used by Mony as an argument, while INT10 BIOS calls do use it -- I just
  62. // ;use di, instead).  The IDC entry is semaphore guarded, and returns 0FE14h if
  63. // ;busy (i.e., at interrupt time).  Retry until you succeed, if you want.  The
  64. // ;HLL interface returns busy as 0xFF14h, and this indicates that a DD is using
  65. // ;Mony at interrupt time.  Retry, again, as required.
  66. //
  67. // ;If you are doing device drivers in something other than assembly, you need
  68. // ;to find out how to go about doing the above tasks before you can use Mony.
  69. // ;For applicaton level stuff, you can forget about all this above, and just use
  70. // ;the stuff below.
  71. //
  72. // ------------------------------------------------------------------------------
  73. // Now, back to our regular programming
  74.  
  75. #define INCL_BASE
  76. #define INCL_DOSDEVIOCTL
  77.  
  78. #include <os2.h>
  79.  
  80. #include <stdlib.h>
  81. #include <string.h>     // only strlen() is used
  82.  
  83. #include "mony_api.h"  // protos to functions in this module are in mony_api.h
  84.  
  85.  
  86. // 00 -----------------------------------
  87. // Zeroes all page memory (unless bit7=1)
  88. // Displays page 0
  89. // Inits all cursor positions to 0,0
  90. // Disables blink/enables intensity
  91.  
  92. ULONG MonySetVideoMode (HFILE monyID, UCHAR videoMode) {
  93.  
  94.    ULONG rc=0;
  95.    ULONG parmLen = sizeof(REGPACK);
  96.    REGPACK iREG;
  97.  
  98.    iREG.ah = 0x00;
  99.    iREG.al = videoMode;
  100.  
  101.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  102.                     &iREG,sizeof(REGPACK),&parmLen,
  103.                     NULL,0,NULL);
  104.  
  105.    return rc;
  106. }
  107.  
  108.  
  109. // 01 ------------
  110. // Set cursor size
  111. // topLine=0x20 disables the cursor
  112.  
  113. ULONG MonySetCursorSize (HFILE monyID, UCHAR topLine, UCHAR bottomLine) {
  114.  
  115.    ULONG rc=0;
  116.    ULONG parmLen = sizeof(REGPACK);
  117.    REGPACK iREG;
  118.  
  119.    iREG.ah = 0x01;
  120.    iREG.ch = topLine;
  121.    iREG.cl = bottomLine;
  122.  
  123.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  124.                     &iREG,sizeof(REGPACK),&parmLen,
  125.                     NULL,0,NULL);
  126.    return rc;
  127. }
  128.  
  129.  
  130. // 02 --------------------------
  131. // Set Cursor Position for Page
  132.  
  133. ULONG MonySetCursorPos (HFILE monyID, UCHAR page, UCHAR row, UCHAR column) {
  134.  
  135.    ULONG rc=0;
  136.    ULONG parmLen = sizeof(REGPACK);
  137.    REGPACK iREG;
  138.  
  139.    iREG.ah = 0x02;
  140.    iREG.bh = page;
  141.    iREG.dh = row;
  142.    iREG.dl = column;
  143.  
  144.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  145.                     &iREG,sizeof(REGPACK),&parmLen,
  146.                     NULL,0,NULL);
  147.    return rc;
  148. }
  149.  
  150.  
  151. // 03 --------------
  152. // Get Cursor Status
  153.  
  154. ULONG MonyGetCursorStatus (HFILE monyID, UCHAR page, PUCHAR row, PUCHAR column, PUCHAR topLine, PUCHAR bottomLine) {
  155.  
  156.    ULONG rc=0;
  157.    ULONG parmLen = sizeof(REGPACK);
  158.    ULONG dataLen = sizeof(REGPACK);
  159.    REGPACK iREG, oREG;
  160.  
  161.    iREG.ah = 0x03;
  162.    iREG.bh = page;
  163.  
  164.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  165.                     &iREG,sizeof(REGPACK),&parmLen,
  166.                     &oREG,sizeof(REGPACK),&dataLen);
  167.    *row = oREG.dh;
  168.    *column = oREG.dl;
  169.    *topLine = oREG.ch;
  170.    *bottomLine = oREG.cl;
  171.    return rc;
  172. }
  173.  
  174.  
  175. // 05 -----------
  176. // Set Video Page
  177.  
  178. ULONG MonySetVideoPage (HFILE monyID, UCHAR page) {
  179.  
  180.    ULONG rc=0;
  181.    ULONG parmLen = sizeof(REGPACK);
  182.    REGPACK iREG;
  183.  
  184.    iREG.ah = 0x05;
  185.    iREG.al = page;
  186.  
  187.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  188.                     &iREG,sizeof(REGPACK),&parmLen,
  189.                     NULL,0,NULL);
  190.    return rc;
  191. }
  192.  
  193.  
  194. // 06 ------
  195. // Scroll Up
  196.  
  197. ULONG MonyScrollUp (HFILE monyID, UCHAR lines, UCHAR attr, UCHAR r0, UCHAR c0, UCHAR r1, UCHAR c1) {
  198.  
  199.    ULONG rc=0;
  200.    ULONG parmLen = sizeof(REGPACK);
  201.    REGPACK iREG;
  202.  
  203.    iREG.ah = 0x06;
  204.    iREG.al = lines;
  205.    iREG.bh = attr;
  206.    iREG.ch = r0;
  207.    iREG.cl = c0;
  208.    iREG.dh = r1;
  209.    iREG.dl = c1;
  210.  
  211.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  212.                     &iREG,sizeof(REGPACK),&parmLen,
  213.                     NULL,0,NULL);
  214.    return rc;
  215. }
  216.  
  217.  
  218. // 07 --------
  219. // Scroll Down
  220.  
  221. ULONG MonyScrollDown (HFILE monyID, UCHAR lines, UCHAR attr, UCHAR r0, UCHAR c0, UCHAR r1, UCHAR c1) {
  222.  
  223.    ULONG rc=0;
  224.    ULONG parmLen = sizeof(REGPACK);
  225.    REGPACK iREG;
  226.  
  227.    iREG.ah = 0x07;
  228.    iREG.al = lines;
  229.    iREG.bh = attr;
  230.    iREG.ch = r0;
  231.    iREG.cl = c0;
  232.    iREG.dh = r1;
  233.    iREG.dl = c1;
  234.  
  235.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  236.                     &iREG,sizeof(REGPACK),&parmLen,
  237.                     NULL,0,NULL);
  238.    return rc;
  239. }
  240.  
  241.  
  242. // 08 ----------------------------------
  243. // Get Character and Attribute at Cursor
  244. //
  245. // An easy enchancement to this routine is to include a cursor position and
  246. // get-save the current position, set to the new, get char/attr, then restore
  247. // the original cursor position.
  248.  
  249. ULONG MonyGetCharAttrAtCursor (HFILE monyID, UCHAR page, PUCHAR character, PUCHAR attr) {
  250.  
  251.    ULONG rc=0;
  252.    ULONG parmLen = sizeof(REGPACK);
  253.    ULONG dataLen = sizeof(REGPACK);
  254.    REGPACK iREG, oREG;
  255.  
  256.    iREG.ah = 0x08;
  257.    iREG.bh = page;
  258.  
  259.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  260.                     &iREG,sizeof(REGPACK),&parmLen,
  261.                     &oREG,sizeof(REGPACK),&dataLen);
  262.    *character = oREG.al;
  263.    *attr = oREG.ah;
  264.    return rc;
  265. }
  266.  
  267.  
  268. // 09 ---------------------------------------
  269. // Write Character(s) and Attribute at Cursor
  270. //
  271. // Does not change cursor position.
  272. //
  273. // An easy enchancement to this routine is to include a cursor position and
  274. // get-save the current position, set to the new, write char/attr, then restore
  275. // the original cursor position.
  276.  
  277. ULONG MonyWriteCharAttrAtCursor (HFILE monyID, UCHAR page, UCHAR character, UCHAR attr, USHORT repCount) {
  278.  
  279.    ULONG rc=0;
  280.    ULONG parmLen = sizeof(REGPACK);
  281.    REGPACK iREG;
  282.  
  283.    iREG.ah = 0x09;
  284.    iREG.al = character;
  285.    iREG.bh = page;
  286.    iREG.bl = attr;
  287.    iREG.cx = repCount;
  288.  
  289.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  290.                     &iREG,sizeof(REGPACK),&parmLen,
  291.                     NULL,0,NULL);
  292.    return rc;
  293. }
  294.  
  295.  
  296. // 0A -------------------------
  297. // Write Character(s) at Cursor
  298. //
  299. // Does not change cursor position.
  300. //
  301. // Uses existing attribute, otherwise similar to 09.
  302.  
  303. ULONG MonyWriteCharAtCursor (HFILE monyID, UCHAR page, UCHAR character, USHORT repCount) {
  304.  
  305.    ULONG rc=0;
  306.    ULONG parmLen = sizeof(REGPACK);
  307.    REGPACK iREG;
  308.  
  309.    iREG.ah = 0x0A;
  310.    iREG.al = character;
  311.    iREG.bh = page;
  312.    iREG.cx = repCount;
  313.  
  314.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  315.                     &iREG,sizeof(REGPACK),&parmLen,
  316.                     NULL,0,NULL);
  317.    return rc;
  318. }
  319.  
  320.  
  321. // 0E ------------------------
  322. // Write Character in TTY mode
  323. //
  324. // Processing control characters:  7=bell, 8=BS, 10=LF, 13=CR.
  325. // Cursor position is updated as appropriate.
  326.  
  327. ULONG MonyWriteCharTTY (HFILE monyID, UCHAR page, UCHAR character) {
  328.  
  329.    ULONG rc=0;
  330.    ULONG parmLen = sizeof(REGPACK);
  331.    REGPACK iREG;
  332.  
  333.    iREG.ah = 0x0E;
  334.    iREG.al = character;
  335.    iREG.bh = page;
  336.  
  337.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  338.                     &iREG,sizeof(REGPACK),&parmLen,
  339.                     NULL,0,NULL);
  340.    return rc;
  341. }
  342.  
  343.  
  344. // 0F -------------
  345. // Get Video Status
  346. //
  347. // Gets the number of columns (80), video mode (7), and active page (0-7).
  348.  
  349. ULONG MonyGetVideoStatus (HFILE monyID, PUCHAR page, PUCHAR columns, PUCHAR videoMode) {
  350.  
  351.    ULONG rc=0;
  352.    ULONG parmLen = sizeof(REGPACK);
  353.    ULONG dataLen = sizeof(REGPACK);
  354.    REGPACK iREG, oREG;
  355.  
  356.    iREG.ah = 0x0F;
  357.  
  358.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  359.                     &iREG,sizeof(REGPACK),&parmLen,
  360.                     &oREG,sizeof(REGPACK),&dataLen);
  361.    *columns = oREG.ah;
  362.    *videoMode = oREG.al;
  363.    *page = oREG.bh;
  364.    return rc;
  365. }
  366.  
  367.  
  368. // 10/3 --------------
  369. // Set Blink/Intensity
  370. //
  371. // Select either blink mode or intensity mode when bit7=1 of attr byte.
  372. // blink=1 sets blink mode.
  373.  
  374. ULONG MonySetBlinkMode (HFILE monyID, UCHAR blink) {
  375.  
  376.    ULONG rc=0;
  377.    ULONG parmLen = sizeof(REGPACK);
  378.    REGPACK iREG;
  379.  
  380.    iREG.ah = 0x10;
  381.    iREG.al = 0x03;
  382.    iREG.bl = blink;
  383.  
  384.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  385.                     &iREG,sizeof(REGPACK),&parmLen,
  386.                     NULL,0,NULL);
  387.    return rc;
  388. }
  389.  
  390. // 10/4 -----------------
  391. // Set Bell Freq/Duration
  392. //
  393. // Set frequency (Hz) and duration (ms) of bell sound on Ctrl-G processing
  394. // during Write TTY or String, where 0 for BOTH turns off the bell.  The
  395. // Ctrl-G is not displayed in any case using WriteTTY or WriteString.  Use
  396. // one of the WriteChar functions to display code 7.
  397.  
  398. ULONG MonySetBellMode (HFILE monyID, USHORT freq, USHORT duration) {
  399.  
  400.    ULONG rc=0;
  401.    ULONG parmLen = sizeof(REGPACK);
  402.    REGPACK iREG;
  403.  
  404.    iREG.ah = 0x10;
  405.    iREG.al = 0x04;
  406.    iREG.bx = freq;
  407.    iREG.cx = duration;
  408.  
  409.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  410.                     &iREG,sizeof(REGPACK),&parmLen,
  411.                     NULL,0,NULL);
  412.    return rc;
  413. }
  414.  
  415.  
  416. // 13 ----------
  417. // Writes String
  418. // without cursor position update
  419.  
  420. ULONG MonyWriteString (HFILE monyID, PSZ strgPtr, UCHAR page, UCHAR attr, UCHAR row, UCHAR col) {
  421.  
  422.    ULONG rc=0;
  423.    ULONG parmLen = sizeof(REGPACK);
  424.    ULONG dataLen;
  425.    REGPACK iREG;
  426.  
  427.    dataLen = strlen(strgPtr);
  428.    if (dataLen) {
  429.  
  430.       iREG.ah = 0x13;
  431.       iREG.al = 0;         // use attribute in .bl, do not update cursor position
  432.       iREG.bh = page;
  433.       iREG.bl = attr;
  434.       iREG.cx = dataLen;
  435.       iREG.dh = row;
  436.       iREG.dl = col;
  437.  
  438.       rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  439.                        &iREG,sizeof(REGPACK),&parmLen,
  440.                        strgPtr,strlen(strgPtr),&dataLen);
  441.    }
  442.    return rc;
  443. }
  444.  
  445.  
  446. // 14 -------
  447. // Read Block
  448. //
  449. // Read page memory block to buffer.  Buffer must be large enough to contain area
  450. // (rows * columns * 2 (*2 for char/attr pairs)).  Page memory is read, and need
  451. // not be the active display.  This is not a BIOS INT10 routine.
  452.  
  453. ULONG MonyReadBlock (HFILE monyID, PVOID bufferPtr, UCHAR page, UCHAR r0, UCHAR c0, UCHAR rows, UCHAR columns) {
  454.  
  455.    ULONG rc=0;
  456.    ULONG parmLen = sizeof(REGPACK);
  457.    ULONG dataLen;
  458.    REGPACK iREG;
  459.  
  460.    dataLen = rows * columns * 2;
  461.  
  462.    iREG.ah = 0x14;
  463.    iREG.bh = page;
  464.    iREG.ch = r0;
  465.    iREG.cl = c0;
  466.    iREG.dh = rows;
  467.    iREG.dl = columns;
  468.  
  469.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  470.                     &iREG,sizeof(REGPACK),&parmLen,
  471.                     bufferPtr,dataLen,&dataLen);
  472.    return rc;
  473. }
  474.  
  475.  
  476. // 15 --------
  477. // Write Block
  478. //
  479. // Write buffer to page memory and screen if page is active.
  480. // Buffer must be same size as (rows * columns * 2 (*2 for char/attr pairs)).
  481. // This is not a BIOS INT10 routine.
  482.  
  483. ULONG MonyWriteBlock (HFILE monyID, PVOID bufferPtr, UCHAR page, UCHAR r0, UCHAR c0, UCHAR rows, UCHAR columns) {
  484.  
  485.    ULONG rc=0;
  486.    ULONG parmLen = sizeof(REGPACK);
  487.    ULONG dataLen;
  488.    REGPACK iREG;
  489.  
  490.    dataLen = rows * columns *2;
  491.  
  492.    iREG.ah = 0x15;
  493.    iREG.bh = page;
  494.    iREG.ch = r0;
  495.    iREG.cl = c0;
  496.    iREG.dh = rows;
  497.    iREG.dl = columns;
  498.  
  499.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  500.                     &iREG,sizeof(REGPACK),&parmLen,
  501.                     bufferPtr,dataLen,&dataLen);
  502.    return rc;
  503. }
  504.  
  505.  
  506. // 1B -----------------------------------
  507. // Fill 64-byte Table with Mony BIOS Info
  508. // The returned info is slightly modified from standard INT10 to better suit Mony.
  509.  
  510. ULONG MonyGetBiosData (HFILE monyID, PBIOSDATA VBDptr) {
  511.  
  512.    ULONG rc=0;
  513.    ULONG parmLen = sizeof(REGPACK);
  514.    ULONG dataLen = sizeof(BIOSDATA);
  515.    REGPACK iREG;
  516.  
  517.    iREG.ah = 0x1B;
  518.    iREG.bx = 0;
  519.  
  520.    rc = DosDevIOCtl(monyID,IOCTL_MONY,IOCTL_40TH,
  521.                     &iREG,sizeof(REGPACK),&parmLen,
  522.                     VBDptr,sizeof(BIOSDATA),&dataLen);
  523.    return rc;
  524. }
  525.  
  526. // o-la-la
  527. // -------
  528.  
  529.